package 日期与时间;

import java.util.Calendar;
import java.util.GregorianCalendar;

public class Calendar_使用 {
    public static void main(String[] args) {
        //获取时间
        Calendar sj= Calendar.getInstance();
        System.out.println(sj);
        int year=sj.get(Calendar.YEAR);
        System.out.println(year);
        int month=sj.get(Calendar.MONTH)+1;
        System.out.println(month);
        int day=sj.get(Calendar.DATE);
        System.out.println(day);
        //调整时间
        sj.set(Calendar.YEAR,2021);
        System.out.println(sj.get(Calendar.YEAR));//2021
        //加减
        sj.add(Calendar.YEAR,1);
        System.out.println(sj.get(Calendar.YEAR));//2022
        System.out.println(sj.getTime());//默认的格式时间Tue Apr 12 16:10:07 CST 2022
        System.out.println(sj.getTimeInMillis());//1649751099747获取时间毫秒值
    }
}
